import {NativeModules} from 'react-native';
import {ToastAndroid} from 'react-native';

const AppCache = Object.create(NativeModules.HttpCache);
AppCache.getAllCache = async function () {
  const [httpCache, imageCache] = await Promise.all([
    this.getHttpCacheSize(),
    this.getImageCacheSize(),
  ]);

  return httpCache + imageCache;
};
AppCache.clearAllCache = async function () {
  try {
    await Promise.all([this.clearImageCache(), this.clearCache()]);
    ToastAndroid.showWithGravity('删除成功', 2000, ToastAndroid.TOP);
  } catch {
    ToastAndroid.showWithGravity('删除失败', 2000, ToastAndroid.TOP);
    return Promise.reject();
  }
};
export default AppCache;
